<template>
  <div class="modal" v-show="$store.state.isOpenLogin">
    <div class="bgc" @click="closeLogin"></div>
    <div class="content">
      <section class="top">
        <span>登录</span>
        <button class="close" @click="closeLogin">X</button>
      </section>
      <div v-if="wyewm">
        <div class="Ml">
          <img src="../assets/img/wysaomal.png" alt="" />
          <section>
            <h3>扫码登录</h3>
            <img :src="this.ErWeima" alt="" />
            <p>使用<a href="#">网易云音乐APP</a>扫码登录</p>
          </section>
        </div>
        <div class="btns" @click="goQita">选择其他登录模式</div>
      </div>
      <div v-else-if="qita" class="qita">
        <div class="qita_left">
          <div></div>
          <button @click="goQitaLogin">手机号登录</button>
          <button>注册</button>
          <p>
            <input type="checkbox" v-model="checkBox" />
            同意
            <a href="#">《服务条款》</a>
            <a href="#">《隐私政策》</a>
            <a href="#">《儿童隐私政策》</a>
          </p>
        </div>
        <div class="qita_right">
          <ul>
            <li>
              <div class="weixin"></div>
              <h4>微信登录</h4>
            </li>
            <li>
              <div class="qie"></div>
              <h4>QQ登录</h4>
            </li>
            <li>
              <div class="weibo"></div>
              <h4>微博登录</h4>
            </li>
            <li>
              <div class="email"></div>
              <h4>网易邮箱账号登录</h4>
            </li>
          </ul>
          <span class="hui" @click="goQita"> 返回 </span>
        </div>
      </div>
      <div v-else class="phonelogin">
        <div class="ban">
          <input
            class="phonecode"
            type="text"
            placeholder="请输入手机号"
            v-model="phone"
          />
          <div class="yanzheng">
            <input type="text" placeholder="请输入验证码" v-model="code" />
            <button @click="getyanzheng">获取验证码</button>
          </div>
          <button class="loginbtn" @click="LoginFn">登录</button>
          <!-- <span class="pass">密码登录</span> -->
          <div class="qitade">
            <span @click="goQitaLogin">其他登录方式 </span>
            <span>没有账号?其他登录方式 </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  GetYzCodeApi,
  SendCodeApi,
  GetLoginApi,
  GetErweimaApi,
  GetErweimatuApi,
} from "@/request/api";
const validatephone = (phone) => {
  let reg =
    /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
  // 手机号正确 返回true  错误 返回false
  return reg.test(phone.trim());
};
export default {
  data() {
    return {
      //网易云二维码显示
      wyewm: true,
      qita: true,
      phone: "13541726626",
      code: "",
      // 倒计时
      count: 60,

      key: "",
      ErWeima: "",
      //同意
      checkBox: false,
    };
  },
  methods: {
    // 关闭这个模态框
    closeLogin() {
      // console.log(process.env.VUE_APP_STATE_URL + this.$route.path);
      return this.$store.commit("changeIsShowLogin", false);
    },
    //其他登录方式
    goQita() {
      this.wyewm = !this.wyewm;
    },
    goQitaLogin() {
      if (!this.checkBox == true) {
        let toast = {
          content: "请先勾选同意注意事项",
          icon: "info",
        };
        this.$store.dispatch("AsyncToast", toast);
        return;
      }
      this.qita = !this.qita;
    },
    // 点击登录
    async LoginFn() {
      console.log(123);
      let rst = await GetYzCodeApi({
        phone: this.phone,
        captcha: this.code,
      }).then((res) => {
        if (res.data.code == 503) {
          let toast = {
            content: res.data.message,
            icon: "info",
          };
          console.log(rst);
          this.$store.dispatch("AsyncToast", toast);
        }
        if (res.data.code == 200) {
          let toast = {
            content: "登录成功",
            icon: "success",
          };
          console.log(res);
          this.$store.dispatch("AsyncToast", toast);
        }
        this.$store.commit("changeIsShowLogin", false);
        return res;
      });
      GetLoginApi({ phone: this.phone }).then((res) => {
        console.log(res);
      });
    },
    // 获取验证码
    getyanzheng() {
      // 判断有没有手机号
      let result = validatephone(this.phone);
      if (!result) {
        let toast = {
          content: "请正确输入手机号",
          icon: "info",
        };
        this.$store.dispatch("AsyncToast", toast);
        return;
      } else {
        SendCodeApi({ phone: this.phone }).then((res) => {
          console.log(res);
        });
        let toast = {
          content: "发送成功",
          icon: "success",
        };
        this.$store.dispatch("AsyncToast", toast);
      }
    },
  },
  created() {
    GetErweimaApi().then((res) => {
      this.key = res.data.data.unikey;
      console.log(this.key);
      return;
    });
    GetErweimatuApi({ key: this.key, qrimg: "1" }).then((res) => {
      this.ErWeima = res.data.data.qrurl;
      console.log(res);
    });
  },
};
</script>
 
<style lang = "less" scoped>
@import "@/assets/base.less";

.modal {
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 11;
  .bgc {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
  }
  .content {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    width: 660px;
    height: 460px;
    background-color: white;
    .top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 30px;
      background: black;
      span {
        padding-left: 10px;
        font-weight: bold;
        color: #ccc;
      }
      div {
        width: 20px;
        height: 30px;
        color: #ccc;
        cursor: pointer;
      }
    }
    .Ml {
      display: flex;
      img {
        height: 300px;
        margin-left: 150px;
        margin-top: 30px;
      }
      section {
        margin-top: 35px;
        margin-left: 20px;
        h3 {
          text-align: center;
          margin-bottom: 30px;
        }
        img {
          width: 200px;
          height: 200px;
          margin: auto;
        }
        p {
          margin-top: 10px;
        }
      }
    }
    .btns {
      width: 150px;
      height: 30px;
      margin-left: 40%;
      margin-top: 20px;
      line-height: 30px;
      text-align: center;
      border-radius: 15px 15px 15px 15px;
      border: 1px solid #cccfcc;
    }
  }
}
.qita {
  display: flex;
}
.qita_left {
  width: 70%;
  div {
    height: 160px;
    width: 280px;
    background: url(../assets/img/yundenglu.png) no-repeat;
    background-size: contain;
    margin-left: 140px;
    margin-top: 60px;
  }
  button {
    width: 280px;
    margin-bottom: 10px;
    height: 30px;
    border-style: none;
    margin-left: 140px;
    &:nth-of-type(1) {
      background-color: #3787d2;
      color: white;
    }
  }
  p {
    font-size: 14px;
    margin-top: 30px;
    margin-left: 60px;
    a {
      text-decoration: none;
      color: #3787d2;
      &:hover {
        text-decoration: underline;
      }
    }
  }
}
.qita_right {
  border-left: 1px solid #ccc;
  width: 35%;
  padding-left: 20px;
  box-sizing: border-box;
  padding-top: 20px;
  li {
    margin-top: 20px;
    display: flex;

    align-items: center;
    .weixin {
      height: 48px;
      width: 40px;
      background: url(../assets/img/jinglingtu.png) no-repeat -150px -666px;
    }
    .qie {
      height: 48px;
      width: 40px;
      background: url(../assets/img/jinglingtu.png) no-repeat -190px -666px;
    }
    .weibo {
      height: 48px;
      width: 40px;
      background: url(../assets/img/jinglingtu.png) no-repeat -230px -666px;
    }
    .email {
      height: 48px;
      width: 40px;
      background: url(../assets/img/jinglingtu.png) no-repeat -270px -666px;
    }
    h4 {
      padding-left: 10px;
      &:hover {
        text-decoration: underline;
      }
    }
  }
  .hui {
    position: absolute;
    bottom: 20px;
    right: 20px;
  }
}

.phonelogin {
  width: 100%;
  position: relative;
  .phonecode {
    width: 350px;
    height: 30px;
    padding-left: 10px;
    margin-left: 23%;
    margin-top: 80px;
    outline-style: none;
    border-radius: 15px 15px 15px 15px;
  }
  
  .yanzheng {
    box-sizing: border-box;
    input {
      width: 230px;
      height: 30px;
      padding-left: 10px;
      margin-left: 23%;
      border-radius: 15px 15px 15px 15px;
      outline-style: none;
    }
    button {
      margin-left: 20px;
      width: 100px;
      height: 33px;
      color: white;
      border: none;
      border-radius: 15px 15px 15px 15px;
      background-color: @orange;
    }
  }
  .loginbtn {
    width: 350px;
    height: 30px;
    padding-left: 10px;
    margin-top: 20px;
    margin-left: 23%;
    border: none;
    border-radius: 15px 15px 15px 15px;
    background-color: @orange;
    color: white;
    font-weight: bolder;
  }
  .pass {
    display: block;
    margin-left: 20px;
    padding-top: 50px;
    margin-bottom: 30px;
    &:hover {
      color: #3787d2;
      text-decoration: underline;
    }
  }
  .qitade {
    /* width: 300px; */
    display: flex;
    /* justify-content: space-between; */
    justify-content: center;
    span {
      color: #cccfcc;
      margin-top: 20px;
      flex: 1;
      margin-left: 80px;
      &:hover {
        color: #3787d2;
        text-decoration: underline;
      }
    }
  }
}
</style>